<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Get date now
 *
 * @access public
 * @return string
 */
if( ! function_exists('get_date_now'))
{
    function get_date_now()
    {
        return date('Y-m-d H:i:s');
    }
}

/**
 * Get date part of a datetime
 *
 * @access public
 * @param $datetime
 * @return string
 */
if( ! function_exists('get_date'))
{
    function get_date($datetime)
    {
        if ( $datetime == '0000-00-00 00:00:00' ) 
        {
            $date = 'null';
        } 
        else 
        {
            $date = substr($datetime, 0, 10);
        }

        return $date;
    }
}

/**
 * Get short type date format
 *
 * @access public
 * @param $number
 * @param $currency_code
 * @param $currency_value
 * @return string
 */
if( ! function_exists('get_date_short'))
{
    function get_date_short($date = null, $with_time = false)
    {
        $CI =& get_instance();

        if (empty($date))
        {
            $date = get_date_now();
        }

        $year = substr($date, 0, 4);
        $month = (int)substr($date, 5, 2);
        $day = (int)substr($date, 8, 2);
        $hour = (int)substr($date, 11, 2);
        $minute = (int)substr($date, 14, 2);
        $second = (int)substr($date, 17, 2);

        if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year)
        {
            return strftime($CI->lang->get_date_format_short(), mktime($hour, $minute, $second, $month, $day, $year));
        }
        else
        {
            return ereg_replace('2037', $year, strftime($CI->lang->get_date_format_short(), mktime($hour, $minute, $second, $month, $day, 2037)));
        }
    }
}

/**
 * Get long type date format
 *
 * @access public
 * @param $number
 * @param $currency_code
 * @param $currency_value
 * @return string
 */
if( ! function_exists('get_date_long'))
{
    function get_date_long($date = null, $with_time = false)
    {
        $CI =& get_instance();

        if (empty($date))
        {
            $date = get_date_now();
        }

        $year = substr($date, 0, 4);
        $month = (int)substr($date, 5, 2);
        $day = (int)substr($date, 8, 2);
        $hour = (int)substr($date, 11, 2);
        $minute = (int)substr($date, 14, 2);
        $second = (int)substr($date, 17, 2);

        if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year)
        {
            return strftime($CI->lang->get_date_format_long(), mktime($hour, $minute, $second, $month, $day, $year));
        }
        else
        {
            return ereg_replace('2037', $year, strftime($CI->lang->get_date_format_long(), mktime($hour, $minute, $second, $month, $day, 2037)));
        }
    }
}

if( ! function_exists('get_month'))
{
    function get_month()
    {
        $arr = array(
            'jan' => lang('jan'), 
            'feb' => lang('feb'),
            'mar' => lang('mar'),
            'apr' => lang('apr'),
            'may' => lang('may'),
            'jun' => lang('jun'),
            'jul' => lang('jul'),
            'aug' => lang('aug'),
            'sep' => lang('sep'),
            'oct' => lang('oct'),
            'nov' => lang('nov'),
            'dec' => lang('dec')          
        );
        return $arr;
    }
}

if( ! function_exists('get_week'))
{
    function get_week()
    {
        $arr = array(
            'mon' => lang('mon'), 
            'tues' => lang('tues'),
            'wed' => lang('wed'),
            'thur' => lang('thur'),
            'fri' => lang('fri'),
            'sat' => lang('sat'),
            'sun' => lang('sun')          
        );
        return $arr;
    }
}
/* End of file datetime_helper.php */
/* Location: ./system/tomatocart/helpers/datetime_helper.php */